#ifndef __WINGBOT_TICK_H
#define __WINGBOT_TICK_H

#include "stm32f4xx.h"

extern uint8_t _wb_TIM2_enable;
extern uint32_t _wb_TIM2_tick;

#define wing_timer_tick(n) do{\
                               if(_wb_##n##_enable){ \
                                    _wb_##n##_tick++;\
                                   if(_wb_##n##_tick>=600000000U)_wb_##n##_tick=0;\
                               }\
                             }while(0)

#define wing_timer_start(n) do{\
                                _wb_##n##_enable = 1; \
                               }while(0)

#define wing_timer_pause(n) do{\
                                _wb_##n##_enable = 0; \
                               }while(0)

#define wing_timer_restart(n) do{\
                                _wb_##n##_enable = 1; \
                                _wb_##n##_tick = 0; \
                               }while(0)

#define wing_timer_stop(n) do{\
                                _wb_##n##_enable = 0; \
                                _wb_##n##_tick = 0; \
                               }while(0)

#define wing_get_tick(n)   _wb_##n##_tick
                               
#define time_flag_refresh(n) do{    n = 0; \
                                    n##_tick = n##_tick == 1000?0:n##_tick+1;}while(0)

#if defined __cplusplus
extern "C" {
#endif
    
    typedef struct TimeFlags{
        uint32_t ms1;
        uint32_t ms1_tick;
        uint32_t ms10;
        uint32_t ms10_tick;
        uint32_t ms100;
        uint32_t ms100_tick;
    }TimeFlags_T;
    
    extern TimeFlags_T time_flags;
    
#if defined __cplusplus
}
#endif

#endif
